<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\erp\model;

use think\Model;

/**
 * 商品规格 设置
 * @package app\erp\model
 */
class ErpGoodsPurchaseOrderSku extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_erp_goods_purchase_order_sku';

    /**
     * 计算采购单-预计采购总价
     */
    public function reckonCg($purchase_id)
    {
        if(!isset($purchase_id) || empty($purchase_id)){
            return array_out(-1001, 'error1');
        }else{
            $sql = "SELECT sum(pay) FROM (SELECT num*price AS pay FROM `".$this->table."` where purchase_id=".$purchase_id.") pay
";
            $res = $this->query($sql);
            if($res){
                return array_out(200, 'success', $res[0]['sum(pay)']);
            }else{
                return array_out(-1001, 'error');
            }
        }
    }


    /**
     * 计算采购单-实际入库总价
     */
    public function reckonRk($purchase_id)
    {
        if(!isset($purchase_id) || empty($purchase_id)){
            return array_out(-1001, 'error1');
        }else{
            $sql = "SELECT sum(pay) FROM (SELECT rk_num*price AS pay FROM `".$this->table."` where purchase_id=".$purchase_id.") pay
";
            $res = $this->query($sql);
            if($res){
                return array_out(200, 'success', $res[0]['sum(pay)']);
            }else{
                return array_out(-1001, 'error');
            }
        }
    }
}
